<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>命令模板</title>
	<link rel="stylesheet" href="./css/css.css">
	<link rel="stylesheet" href="./css/leftBar.css">
	<script type="text/javascript" src="./js/jquery-1.8.3.js"></script>
	<link type="text/css" rel="Stylesheet" href="./css/generalCMD.css" />
	<script type="text/javascript" src="./js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="./js/messagecenter.js"></script>
	<script type="text/javascript" src="./js/common.js"></script>
	<script type="text/javascript" src="./js/jquery.page.js"></script>
	<link rel="stylesheet" href="./css/jquery.page.css">
	<style type="text/css">
		.app_text{
			color:#04A0E9;
			cursor:pointer;
			margin-left:20px;
		}
		.app_text1{
			color:#04A0E9;
			cursor:pointer;
		}
		.page-split input{
			display:inline;
			margin:0px 4px;
		}
		.app_del{
			cursor:pointer;
			margin-left:20px;
	        color: #414B54;
		}
		.text_color{
			color:#A6A6A6;
			text-align: left;
			text-indent: 12px;
		}
		.text_name{
			text-align:left;
			text-indent: 12px;
		}
		.app_no{
			background-color: #83BE00;
			width: 50px;
			height: 18px;
			margin-left: 16%;
			text-indent: 4px;
			border-radius: 4px;
			color: #FFFFFF;
			font-weight: 600;
			padding-top: 2px;
		}
		
	</style>
	<script>
        /**菜单显示*/
        $(function(){
            $(".level22").show();
            $(".general").addClass("checked");
            $(".comm").removeClass("checked");
            $(".phy").removeClass("checked");
            $(".logic").removeClass("checked");
        });

	</script>

</head>
<body>
<div class="left_content">
	<div class="left_block1">
		<div class="left_logo"></div>
		<div class="left_title">品牌数据库编辑器，高效工作，人性化交互</div>
		<div class="left_icons">
			<div class="left_icon1"></div>
			<div class="left_icon2"></div>
			<div class="left_icon3"></div>
		</div>
	</div>
	<div class="left_block2">
		<div class="left_menu" onclick="window.location.href='physical_topology_library';">拓扑文件库</div>
		<div class="left_menu" onclick="window.location.href='logical_application_library';">逻辑预案库</div>
		<div class="left_menu" onclick="window.location.href='deploy_topology_library';">部署库</div>
		<div class="left_menu monitor">监控</div>
		<div class="left_menu level2" >
			<div class="level2Border phy" onclick="window.location.href='physical_monitors';">
				物理监控
			</div>
		</div>
		<div class="left_menu level2" >
			<div class="level2Border logic" onclick="window.location.href='logical_monitors';">
				逻辑监控
			</div>
		</div>
		<div class="left_menu other">其他</div>
		<div class="left_menu  level22" >
			<div class="level22Border comm" onclick="window.location.href='commonCMD';">
				我的常用命令
			</div>
		</div>
		<div class="left_menu level22" >
			<div class="level22Border general" onclick="window.location.href='generalCMD';">
				命令模板
			</div>
		</div>
	</div>
	<form th:action="@{/logout}" method="post" >
		<div class="left_block3">
			<div class="left_title">快捷管理机箱、板卡、芯片，提高工作效率便捷查找功能相关物理和逻辑链接，高效编辑请登陆BDE账号</div>
			<button class="bigmoniter" type="button" onclick="showBig();" style="cursor:pointer;">大屏监控</button>
			<button class="login"  type="submit">注销</button>
		</div>
	</form>
</div>
<div class="right_content" >
	<form id="form1">
		<input type="hidden" id="curIndex" value="0"/>
		<input type="hidden" id="maxPage" value="0"/>
		<input type="hidden" id="curId" name="curId">
		<input type="hidden" id="id" name="id">
		<div class="top-bar">
			<div style="float:left;">用户通用命令库<br>
				<span  class="text_color"  style="font-size: 13px;">General&nbsp;command&nbsp;library</span>
			</div>

			<div class="top_input" style="float:right; height:36px;margin-top: 12px;">
				<div>
					<select class="chtype" id="condition1">
						<option value="0" select>选择类型筛选</option>
						<option value="1">1</option>
						<option value="2">2</option>
					</select>
				</div>
				<button class="search" type="button">搜索</button>
				<input class="s_input" type="text" id="condition2" placeholder="输入关键字搜索"/>
			</div>
		</div>
		<!-- -->
		<div class="table-box" >
			<div class="headerTableDiv">
				<table cellspacing="0" cellpadding="0" style="border-collapse: collapse;">
					<colgroup>
						<col width="10%">
						<col width="10%">
						<col width="47%">
						<col width="23%">
						<col width="10%">
					</colgroup>
					<tr>
						<td>
							<div class="text_name" style="">编号</div>
							<div class="text_color">Serial&nbsp;number</div>
						</td>
						<td>
							<div class="text_name" style="">类型</div>
							<div class="text_color">Type</div>
						</td>
						<td>
							<div class="text_name" style="">命令</div>
							<div class="text_color">The&nbsp;command</div>
						</td>
						<td>
							<div class="text_name" style="">备注</div>
							<div class="text_color">note</div>
						</td>
						<td>
							<div class="text_name"style="">操作</div>
							<div class="text_color" style="">operation</div>
						</td>
					</tr>
				</table>
			</div>
			<div class="contentTableDiv">
				<table cellspacing="0" cellpadding="0" style="border-collapse: collapse;width:100%;" >
					<colgroup>
						<col width="10%">
						<col width="10%">
						<col width="47%">
						<col width="23%">
						<col width="10%">
					</colgroup>
					<tbody id="contentTableTbody"></tbody>
				</table>
			</div>
		</div>
		<!-- 分页 -->
		<div class="page-split">
            <div id="page" style="float:left;"></div>
            <div class="page_count text_color" style="float:right;font-size:13px;">共0条/0页</div>
        </div>
		<!-- 底部 -->
		<div class="bottom">
			<div class="f0">
				<div>编辑</div>
				<div style="color:#DBDDDC;">Edit</div>
			</div>
			<div class="edit" style="height:150px;">
				<div class="f1">
					<div>类型&nbsp;:</div>
					<div>
						<select id="newType" >
							<option value="0" selected>选择类型</option>
							<option value="1">1</option>
							<option value="2">2</option>
						</select>

					</div>
				</div>
				<div class="f2">
					<div>备注&nbsp;:</div>
					<div><input id="newNote" type="text" placeholder="输入备注信息" value=""></div>
				</div>
				<div class="f3">
					<div>命令&nbsp;:</div>
					<div style="width:90%;"><textarea id="newCommand" class="contentTextTextArea2" placeholder="输入命令内容"></textarea></div>
				</div>
			</div>
			<div class="bt-btn" style="position: absolute;width:100%;bottom:20px;left:10px;">
				<button class="btn-s" type="button" onclick="connect()">立即执行</button>
				<button class="btn-s" type="button" onclick="update()" >保存</button>
			</div>
		</div>
	</form>
</div>
<!--查询弹窗-->
<div class="pop_content" id="showInfo" style="display:none;">
	<div class="pop_block">
		<div class="pop_barInfo" >
			<div style="font-size: 18px;">搜索</div>
		</div>
		<div class="exit_pop" ><img style="cursor:pointer;" alt="" src="./images/bsk/pop_exit.png" onclick="exit_pop();"></div>
		<div class="pop_input">
			<button class="searchAll" type="button">搜索</button>
			<input class="s_input" id="condition" type="text" name="" placeholder="输入编号或名称搜索"/>
			<button class="s_right" onclick="reset()" type="button">重置</button>
		</div>
		<div class="headerTableDiv2">
			<table cellspacing="0" cellpadding="0" style="border-collapse: collapse;">
				<colgroup>
					<col width="20%">
					<col width="20%">
					<col width="20%">
					<col width="20%">
					<col width="20%">
				</colgroup>
				<tr>
					<td><div>序号</div></td>
					<td><div>APP名称</div></td>
					<td><div>类型</div></td>
					<td><div>状态</div></td>
					<td><div>备注</div></td>
				</tr>
			</table>
		</div>
		<div class="contentTableDiv2">
			<table cellspacing="0" cellpadding="0" style="border-collapse: collapse;width:100%;" >
				<colgroup>
					<col width="20%">
					<col width="20%">
					<col width="20%">
					<col width="20%">
					<col width="20%">
				</colgroup>
				<tbody class="popTbody"></tbody>
			</table>
		</div>
	</div>
</div>
<!--CMD弹窗-->
<div class="pop_content3" id="showInfo3" style="display:none;">
	<div class="pop_block3">
		<div class="pop_barInfo" >
			<div style="font-size: 14px;color:#434C53">控制台</div>
			<div style="font-size: 12px;color:#989898">The&nbsp;console</div>
		</div>
		<div class="exit_pop" ><img style="cursor:pointer;" alt="" src="./images/bsk/pop_exit.png" onclick="exit_pop3();"></div>
		<div class="contentText">
			<textarea class="contentTextTextArea"></textarea>
		</div>
		<div class="pop_excute">
			<button class="excute" type="button" onclick="issuedCommand();">立即执行</button>
			<input class="ex_input" id="command" type="text" name="" placeholder="输入命令"/>
			<button class="ex_reset" type="button">隐藏</button>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
    $(".ex_reset").on("click",function(){
        $(".pop_excute").hide();
    });
    $(function(){
        $(".search").on("click",function(){
        	var curIndex = $("#curIndex").val();
            var name_like1 = $("#condition1").val();
            var name_like2 = $("#condition2").val();
            getList(0,name_like1,name_like2);
        });
    });
    /*命令执行*/
	function issuedCommand(){
		$.ajax({
            url: "[[@{/gate_way/issued_command}]]",
            data:{command:$("#command").val()},
            contentType: "application/json",
            type: "POST",
            dataType:"JSON"
        }).done(function (result) {
        	alert("执行成功");
        });
	}
    function edit(obj,id){
		var tds = $(obj).parent().parent().find("td");
		$("#id").val(id);
		$("#newType").val($(tds[1]).find("div").html());
		$("#newCommand").val($(tds[2]).find("div").html());
		$("#newNote").val($(tds[3]).find("div").html());
	}
    function connect(){
        alert("立即执行");
    }
    function update(){
         var url='[[@{/universal_command_library/save}]]';
 		var param = {"command":$("#newCommand").val(),"id":$("#id").val(),"no":$("#newNote").val(),"type":$("#newType").val()};
         $.ajax({
         	url:url,
         	data:JSON.stringify(param),
         	dataType:"JSON",
         	type:"POST",
         	contentType:"application/json"
         }).done(function(data){
             if(data){
                 $("#newType").val("");
                 $("#newCommand").val("");
                 $("#newNote").val("");
                 $("#id").val("");
                 alert("保存成功");
                 location.reload();
             };
         });
    }
    function delete2(id){
		if(id==null){
			aler("id不能为空!");
			return false;
		}
		var url='[[@{/universal_command_library/delete}]]';
		$.post(url,{id:id},"JSON").done(function(data){
			if(data.success){
				alert("删除成功");
				location.reload();
			}
		});
	}
    /*列表内容*/
    function addData(data,total,pageSize){
        var maxPage = Math.ceil(total/pageSize);
        $("#maxPage").val(maxPage);
	    pageCal(1,maxPage,total);
        $("#contentTableTbody").empty();
        var html = '';
        $.each(data,function(k,v){
            html += '<tr>';
            html += '<td><div id="no" class="app_no">NO.'+v.id+'</div></td >';
            if(v.type){
				html += '<td><div id="type" class="app_text1" style="cursor:default;">'+v.type+'</div></td>';
			}else{
				html += '<td><div id="type" class="app_text1" style="cursor:default;"></div></td>';
			}
			if(v.command){
				html += '<td style="text-indent: 0px;"><div id="command" class="text_color">'+v.command+'</div></td>';
			}else{
				html += '<td style="text-indent: 0px;"><div id="command" class="text_color"></div></td>';
			}
			if(v.no){
				html += '<td ><div id="note">'+v.no+'</div></td>';
			}else{
				html += '<td ><div id="note"></div></td>';
			}
            html += '<td style="text-indent: 0px;">';
            html += '<a class="app_text edit" onclick="edit(this,'+v.id+');">编辑</a>';
            html += '<a class="app_del" onclick="delete2('+v.id+');">删除</a>';
            html += '</td>';
            html += '</tr>';
        });
        $("#contentTableTbody").append(html);
        tableSum();
    }
    var allData=[];
    $(function () {
    	getList();
    });
    function getList(curIndex,name_like1,name_like2){
       	var url = '[[@{/universal_command_library/query}]]';
        $("#curIndex").val(curIndex);
        var param = {
               "pageable.page":curIndex,
               "pageable.start":curIndex*25,
               "pageable.size":25,
               "pageable.sort":"[]",
               "params.type_eq":name_like1
           };
        if(name_like2){
			param.command_like=name_like2+"%";
		}
        $.post(url,param,"JSON").done(function(data){
            if(data){
                var dataList = data.data;
                allData=dataList;
                $("#contentTableTbody").empty();   
                if(dataList&&dataList.length>0){
                    addData(dataList,dataList.length,25);
                }
            }
        });
    }
    /*CMD弹窗*/
    function open_pop2(){
        $("#showInfo3").show();
    }
    function exit_pop3(){
        $("#showInfo3").hide();
    }
    /*查询弹窗*/
    function open_pop(){
        $("#showInfo").show();
        $(".searchAll").on("click",function () {
            alert("全局搜索");
            var dataArr = [];
            for(i=1;i<=20;i++){
                var dataJson = {};
                dataJson.no = i;
                dataJson.name = "OX8E_"+i;
                dataJson.type="string";
                dataJson.state = i;
                dataJson.note = "string";
                dataArr.push(dataJson);
            }
            addDataPop(dataArr);
            tableSum();
        });
    }
    function reset(){
        $("#condition").val("");
    }
    function addDataPop(data){
        $(".contentTableDiv2 .popTbody").empty();
        var html = '';
        $.each(data,function(k,v){
            html += '<tr>';
            html += '<td>'+v.no+'</td>';
            html += '<td>'+v.name+'</td>';
            html += '<td>'+v.type+'</td>';
            html += '<td>'+v.state+'</td>';
            html += '<td>'+v.note+'</td>';
            html += '</tr>';
        });
        $(".contentTableDiv2 .popTbody").append(html);
    }
    function exit_pop(){
        $("#showInfo").hide();
    }
    function tableSum() {
        $(".contentTableDiv2").scrollTop(10);// 控制滚动条下移10px
        if ($(".contentTableDiv2").scrollTop() > 0) {
            var scrollWidth = getScrollbarWidth();
            $(".contentTableDiv2").css("right",(20-scrollWidth)+"px");
        } else {
            $(".contentTableDiv").css("right", 20 + "px");

            $(".contentTableDiv2 table").css("width", "100%");
        }
        $(".contentTableDiv").scrollTop(0);// 滚动条返回顶部
    }

    function getScrollbarWidth() {
        var odiv = document.createElement('div'),//创建一个div
            styles = {
                width: '100px',
                height: '100px',
                overflowY: 'scroll'//让他有滚动条
            }, i, scrollbarWidth;
        for (i in styles) odiv.style[i] = styles[i];
        document.body.appendChild(odiv);//把div添加到body中
        scrollbarWidth = odiv.offsetWidth - odiv.clientWidth;//相减
        odiv.remove();//移除创建的div
        return scrollbarWidth;//返回滚动条宽度
    }
    /*分页*/
    function pageCal(curIndex, pageCount, totalCount) {
			$("#page").Page({
			  totalPages: pageCount,//分页总数
			  liNums: 7,//分页的数字按钮数(建议取奇数)
			  activeClass: 'activP', //active 类样式定义
			  callBack : function(page){
					//console.log(page);
			        $("#contentTableTbody").empty();
					 var newAllData=[];
					for(var i=(page-1)*25;i<allData.length;i++){
						newAllData.push(allData[i]);
					}
					var html = '';
			        $.each(data,function(k,v){
			            html += '<tr>';
			            html += '<td><div id="no" class="app_no">NO.'+(k+(page-1)*25) +'</div></td >';
			            if(v.type){
							html += '<td><div id="type" class="app_text1" style="cursor:default;">'+v.type+'</div></td>';
						}else{
							html += '<td><div id="type" class="app_text1" style="cursor:default;"></div></td>';
						}
						if(v.command){
							html += '<td style="text-indent: 0px;"><div id="command" class="text_color">'+v.command+'</div></td>';
						}else{
							html += '<td style="text-indent: 0px;"><div id="command" class="text_color"></div></td>';
						}
						if(v.no){
							html += '<td ><div id="note">'+v.no+'</div></td>';
						}else{
							html += '<td ><div id="note"></div></td>';
						}
			            html += '<td style="text-indent: 0px;">';
			            html += '<a class="app_text edit" onclick="edit(this,'+v.id+');">编辑</a>';
			            html += '<a class="app_del" onclick="delete2('+v.id+');">删除</a>';
			            html += '</td>';
			            html += '</tr>';
			        });
			        $("#contentTableTbody").append(html);
			        tableSum();
			  }
		  });
        $(".page-split .page_count").html('共' + totalCount + '条/' + pageCount + '页');
	}
    function showBig(){
		window.location.href="physical_monitors2"
	}
</script>
</html>
